﻿using System.ComponentModel;
using System.Windows;
using System.Windows.Input;

using WpfApp1.Command;
using WpfApp1.Model;

namespace WpfApp1.ViewModel;

class UserViewModel : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler? PropertyChanged;


    private User User = new();

    public string Account
    {
        get { return User.Account; }

        set
        {
            User.Account = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Account"));

        }
    }

    public string Pwd
    {
        get { return User.Password; }

        set
        {
            User.Password = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Pwd"));

        }
    }


    /// <summary>
    /// 用户属性绑定，前端还要奖赏UserModel.什么才能加载,用上面方法可以只显示指定字段，不向下面显示所有字段
    /// </summary>
    //public User UserModel 
    //{

    //    get {
    //        if (User == null) {

    //            User = new();
    //        }
    //        return User;
    //    }

    //    set {

    //        User = value;
    //        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("User"));

    //    }
    //}

    public void Login()
    {
        if (Account == "123" & Pwd == "123")
        {
            MessageBox.Show("OK");
        }
        else
        {
            Account = "";
            Pwd = "";
            MessageBox.Show("错误用户或密码");

        }
    }


    public ICommand Command { get { return new DoCommand(Login); } }

}